/**
 * 
 */
package io.gitee.falllee.dao.core;

import java.util.ArrayList;
import java.util.List;

import io.gitee.falllee.dao.model.BaseDaoConfig;
import io.gitee.falllee.dao.util.DaoUtils;
import io.gitee.falllee.dao.util.FilterPlus;

/**
 * @author batty
 * @date 2022-06-28
 *
 */
public class SelectDistinctBuilder<T, V> extends FilterBuilder {
    
    private SelectBuilder<T> selectBuilder;
    
    private String field;
    
    private Class<V> clazzV;
    
    private List<Class<?>> params;
    
    SelectDistinctBuilder(SelectBuilder<T> parent, BaseDaoConfig daoConfig, FilterPlus filter, String field,
            Class<V> clazzV) {
        super(daoConfig, filter);
        this.selectBuilder = parent;
        this.field = field;
        this.clazzV = clazzV;
    }
    
    public SelectDistinctBuilder<T, V> addChildrenClass(Class<?> clazz) {
        if (params == null) {
            params = new ArrayList<>();
        }
        params.add(clazz);
        return this;
    }
    
    public List<V> select() {
        Class<?>[] pars = DaoUtils.listClass2Array(params);
        return selectBuilder.selectDistinct(filter, field, clazzV, pars);
    }
}
